package com.fz.song.mcos.service.impl;

import com.fz.song.mcos.entity.McUser;
import com.fz.song.mcos.service.IMcUserCustomService;
import com.fz.song.mcos.vo.userdetails.MyUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailsService implements UserDetailsService {


    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private IMcUserCustomService userCustomService;




    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        McUser user = userCustomService.getByUserName(username);
        if (user == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }

        return new MyUserDetails(user);
    }
}
